package com.example.demo;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

import org.apache.commons.io.FileUtils;
import org.jsoup.Connection.Response;
import org.jsoup.Jsoup;
import org.junit.Test;

public class DownPic {
	String path = Thread.currentThread().getContextClassLoader().getResource("").getPath();
//	@Test
	public void downPics() throws IOException {

		URL url = new URL("https://wxt.sinaimg.cn/mw1024/9d52c073gy1g8xxgljffqj20sg16otjs.jpg");

		URLConnection openConnection = url.openConnection();
		openConnection.setReadTimeout(1000);
		openConnection.setConnectTimeout(1000);

		InputStream openStream = url.openStream();
		FileUtils.copyInputStreamToFile(openStream, new File(path, "112.jpg"));
		System.out.println(path);

	}

//	@Test
	public void downPic() throws IOException {
		URL url = new URL("https://i5.meizitu.net/2019/06/22c01.jpg");
		URLConnection openConnection = url.openConnection();
		openConnection.setReadTimeout(1000);
		openConnection.setConnectTimeout(1000);
		InputStream openStream = url.openStream();
		FileUtils.copyInputStreamToFile(openStream, new File(path, "113.jpg"));

	}

//	@Test
	public void downPicJsoup() throws IOException {
		URL url = new URL("https://i5.meizitu.net/2019/06/22c01.jpg");
		Response execute = Jsoup.connect(url.toString()).ignoreContentType(true).referrer("https://www.mzitu.com").execute();
	
		FileUtils.copyInputStreamToFile(execute.bodyStream(), new File(path, "113jsoup.jpg"));

	}
}
